package com.aide.simplification.global.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.ecs.html.Script;

public class InitSuggestTag extends TagSupport {
	private static final long serialVersionUID = -5318708929333274100L;
	private String dwrjs = "";

	public int doEndTag() throws JspException {
		JspWriter out = pageContext.getOut();
		String contextPath=pageContext.getServletContext().getContextPath();
		try {
			String[] dwrjss = dwrjs.split(";");
			for (int i = 0; i < dwrjss.length; i++) {
				String js = dwrjss[i];
				if (!js.equals("")) {
					Script script1 = new Script();
					script1.setType("text/javascript");
					script1.setSrc(contextPath + "/dwr/interface/" + js + ".js");
					out.println(script1.toString());
				}
			}
			Script script2 = new Script();
			script2.setSrc(contextPath + "/dwr/engine.js");
			script2.setType("text/javascript");
			out.println(script2.toString());

			Script script3 = new Script();
			script3.setSrc(contextPath + "/js/jquery.js");
			script3.setType("text/javascript");
			out.println(script3.toString());

			Script script = new Script();
			script.setType("text/javascript");
			script.setTagText("var $j;if(!$j){$j = jQuery.noConflict()};");
			try {
				out.println(script.toString());
			} catch (IOException e) {
			}

			Script script4 = new Script();
			script4.setSrc(contextPath + "/js/suggest.js");
			script4.setType("text/javascript");
			out.println(script4.toString());
		} catch (IOException e) {
		}
		return EVAL_PAGE;
	}
	public String getDwrjs() {
		return dwrjs;
	}

	public void setDwrjs(String dwrjs) {
		this.dwrjs = dwrjs;
	}
}
